<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script src="js/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <script src="js/myjs.js"></script>
    <link rel="stylesheet" href="css/bootstrap.min.css"/>
    <style>
        #result{
            color: gray;
            float: right;
        }
        .showCount{
            color: red;
            font-size: 20px;
            font-weight: bold;
        }
        .form-control {
            width: 200px;
            display: inline-block;
            height: 40px;
        }

        #docAdd h4 {
            text-align: center;
        }

        .lh-1 tr {
            height: 40px;
        }
    </style>
</head>
<body>
<div>
    <form id="queryForm">
        籍贯：<input name="grand" id="grand" class="form-control">
        朝代：<input name="dynName" id="dynName" class="form-control">
        姓、名、字：<input name="docName" id="docName1" class="form-control">
        <input type="button" id="btnQuery" class="btn btn-primary" value="查询">
        &nbsp;&nbsp;&nbsp;<input type="button" id="btnAll" class="btn btn-primary" value="所有重复">
    </form>
    <div id="result">本次查询共<span class="showCount" id="pageCount"></span>页，
        <span class="showCount" id="listCount"></span>条记录
    </div>
</div>
<table class="table table-hover" >
    <tr class="table-active">
        <td>编号</td><td>朝代</td><td>省份</td><td>城市</td><td>县</td><td>姓名</td>
        <td>生卒年</td><td>备注</td><td>操作</td>
    </tr>
    <tbody id="tbdoc"></tbody>
</table>
<nav aria-label="Page navigation example">
    <ul class="pagination"></ul>
</nav>
<!--js代码-->
<script>
    $(function() {
        $("#btnQuery").on("click",function () {
            findDoctor(1,8);
        })
        $("#btnAll").on("click",function () {
            findDoctorRepeat(1,8);
        })
    })
    function findDoctor(page,size) {
        $.get(
            '/doctor/findDoctor',
            $("#queryForm").serialize()+"&page="+page+"&size="+size,
            function (pageInfo) {
                let tb=$("#tbdoc");
                tb.empty();
                let dlist=pageInfo.list;
                for(let i in dlist){
                    let tr=`<tr>
                                   <td>${dlist[i].docId} </td>
                                   <td>${dlist[i].dynName} </td>
                                   <td>${dlist[i].provName} </td>
                                   <td>${dlist[i].city} </td>
                                   <td>${dlist[i].county} </td>
                                   <td>${dlist[i].dname}</td>
                                   <td>${dlist[i].begin_end} </td>
                                   <td width="300px">${dlist[i].memo} </td>
                                    <td><button type="button" onclick="doctorDel(${dlist[i].docId})"
                                    class="btn btn-primary" data-toggle="modal" data-target="#docModal">删除</button>
                                    </td>
                                </tr>`;
                    tb.append(tr);
                }
                let liFirst=pageInfo.isFirstPage?"":`<li class="page-item"><a class="page-link" href="javascript:findDoctor(${page-1},${size})">上一页</a></li>`;

                let li="";
                for(let i in pageInfo.navigatepageNums) {
                    let pn=pageInfo.navigatepageNums[i];
                    li += `<li class="page-item"><a class="page-link" href="javascript:findDoctor(${pn},${size})">${pn}</a></li>`
                }
                let liLast=pageInfo.isLastPage?"":`<li class="page-item"><a class="page-link" href="javascript:findDoctor(${page+1},${size})">下一页</a></li>`;
                $(".pagination").empty();
                $(".pagination").append(liFirst+li+liLast);
                $("#pageCount").html(pageInfo.pages);
                $("#listCount").html(pageInfo.total);
            },'json'
        );
    }

    /*查找所有重复医家*/
    function findDoctorRepeat(page,size) {
        $.get(
            '/doctor/findDoctorRepeat?page='+page+'&size='+size,
            function (pageInfo) {
                let tb=$("#tbdoc");
                tb.empty();
                let dlist=pageInfo.list;
                for(let i in dlist){
                    let tr=`<tr>
                                   <td>${dlist[i].docId} </td>
                                   <td>${dlist[i].dynName} </td>
                                   <td>${dlist[i].provName} </td>
                                   <td>${dlist[i].city} </td>
                                   <td>${dlist[i].county} </td>
                                   <td>${dlist[i].dname}</td>
                                   <td>${dlist[i].begin_end} </td>
                                   <td width="300px">${dlist[i].memo} </td>
                                    <td><button type="button" onclick="doctorDel(${dlist[i].docId})"
                                    class="btn btn-primary" data-toggle="modal" data-target="#docModal">删除</button>
                                    </td>
                                </tr>`;
                    tb.append(tr);
                }
                let liFirst=pageInfo.isFirstPage?"":`<li class="page-item"><a class="page-link" href="javascript:findDoctorRepeat(${page-1},${size})">上一页</a></li>`;

                let li="";
                for(let i in pageInfo.navigatepageNums) {
                    let pn=pageInfo.navigatepageNums[i];
                    li += `<li class="page-item"><a class="page-link" href="javascript:findDoctorRepeat(${pn},${size})">${pn}</a></li>`
                }
                let liLast=pageInfo.isLastPage?"":`<li class="page-item"><a class="page-link" href="javascript:findDoctorRepeat(${page+1},${size})">下一页</a></li>`;
                $(".pagination").empty();
                $(".pagination").append(liFirst+li+liLast);
                $("#pageCount").html(pageInfo.pages);
                $("#listCount").html(pageInfo.total);
            },'json'
        );
    }

    function doctorDel(mid) {
        let del=confirm("你真的要删除这个医家么？");
        if(!del){
            return;
        }
        $.get(
            '/doctor/doctorDel', {
                docId: mid
            },
            function(n) {
                findDoctorRepeat(1,8);
            }
        );
    }
</script>
</body>
</html>